package com.emser.unc.client.presenter;

import com.emser.unc.client.event.AdminNoSaleReportEvent;
import com.emser.unc.client.event.AdminSaleReportEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class ReportsPresenter implements Presenter {
	private final Display display;
	private SimpleEventBus eventBus;
	
	public interface Display {		    
		    HasClickHandlers getSaleReportButton();
		    HasClickHandlers getNoSaleReportButton(); 
		    Widget asWidget();
	}
	
	public ReportsPresenter(SimpleEventBus eventBus, Display display) {
	    this.display = display;
	    this.eventBus= eventBus;
	    bind();
	    
	}
	private void bind() {
		this.display.getSaleReportButton().addClickHandler(new ClickHandler() {   
		      public void onClick(ClickEvent event) {
		    	 eventBus.fireEvent(new AdminSaleReportEvent());
		      }
		}); 
		this.display.getNoSaleReportButton().addClickHandler(new ClickHandler() {   
		      public void onClick(ClickEvent event) {
		    	  eventBus.fireEvent(new AdminNoSaleReportEvent());
		      }
		}); 
	}
	
	@Override
	public void go(HasWidgets container) {
		container.clear();
	    container.add(display.asWidget());
	}
}
